#pragma once

#include "ExpansionRegion.h"

#include "ExpansionNode.h"

namespace uml {

ExpansionRegion::ExpansionRegion(const QString& umlType)
    : StructuredActivityNode(umlType) {}

void ExpansionRegion::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    StructuredActivityNode::fromJson(json, errorList);
    JsonSerializable::fromJsonArray(inputElements_, "inputElements", json, errorList);
    mode_ = (ExpansionKind)json.value("mode").toInt((int)mode_);
    JsonSerializable::fromJsonArray(outputElements_, "outputElements", json, errorList);
}

void ExpansionRegion::toJson(QJsonObject& json) {
    StructuredActivityNode::toJson(json);
    JsonSerializable::toJsonArray(inputElements_, "inputElements", json);
    json.insert("mode", (int)mode_);
    JsonSerializable::toJsonArray(outputElements_, "outputElements", json);
}

/// <summary>
/// inputElements getter
/// The ExpansionNodes that hold the input collections for the ExpansionRegion.
/// </summary>
vector<shared_ptr<ExpansionNode>>& ExpansionRegion::inputElements() {
    return inputElements_;
}

/// <summary>
/// mode getter
/// The mode in which the ExpansionRegion executes its contents. If parallel,
/// executions are concurrent. If iterative, executions are sequential. If stream, a
/// stream of values flows into a single execution.
/// </summary>
ExpansionKind ExpansionRegion::mode() const {
    return mode_;
}

/// <summary>
/// mode setter
/// The mode in which the ExpansionRegion executes its contents. If parallel,
/// executions are concurrent. If iterative, executions are sequential. If stream, a
/// stream of values flows into a single execution.
/// </summary>
void ExpansionRegion::setMode(ExpansionKind value) {
    mode_ = value;
}

/// <summary>
/// outputElements getter
/// The ExpansionNodes that form the output collections of the ExpansionRegion.
/// </summary>
vector<shared_ptr<ExpansionNode>>& ExpansionRegion::outputElements() {
    return outputElements_;
}

} // namespace uml
